/*
 * Copyright (C) 2015 Miquel Sas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package traderlib.core.data.entity;

/**
 * Entity iterator meant to to iterate through huge entity lists. Normal usage is like usual Java iterators. By default,
 * when the iterator reaches the end of the list it closes the underlying persistence source, but it is a good practice
 * to close it always because if the loop breaks without reaching the end it can reamin opened.
 *
 * @author Miquel Sas
 */
public interface EntityIterator extends Iterable<Entity> {

	/**
	 * Check if there is another available entity in the list and moves the cursor pointing to the next entity.
	 *
	 * @return A boolean.
	 * @throws EntityException
	 */
	public boolean hasNext() throws EntityException;

	/**
	 * Retrieves the next entity.
	 *
	 * @return The next entity.
	 * @throws EntityException
	 */
	public Entity next() throws EntityException;

	/**
	 * Close the underlying data source.
	 *
	 * @throws EntityException
	 */
	public void close() throws EntityException;
}
